package server

import (
	v1 "Cosmos.Communication/api/v1"
	v2 "Cosmos.Communication/api/v2"
	"Cosmos.Communication/infrastructure/grpc"
	"Cosmos.Communication/internal/conf"
	"Cosmos.Communication/internal/service"
	"github.com/go-kratos/kratos/v2/log"
	"github.com/go-kratos/kratos/v2/transport"
)

// NewGRPCServer new a gRPC server.
func NewServer(c *conf.Config, dataset *service.DataSetService, logger log.Logger, health *service.ProcessorHealthServiceService, runtime *service.ProcessorRuntimeServiceService) transport.Server {
	var opts = []grpc.ServerOption{}
	if c.Processor.Grpc.Addr != "" {
		opts = append(opts, grpc.Address(c.Processor.Grpc.Addr))
	}
	if c.Processor.Grpc.Network != "" {
		opts = append(opts, grpc.Network(c.Processor.Grpc.Network))
	}

	srv := grpc.NewGrpcServer(opts...)
	v2.RegisterRpcDataSetServiceServer(srv, dataset)
	v1.RegisterProcessorHealthServiceServer(srv, health)
	v1.RegisterProcessorRuntimeServiceServer(srv, runtime)
	return srv
}
